package com.wwj.airline.Controller;

import com.wwj.airline.pojo.AirWay;
import com.wwj.airline.Dao.AirWayRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/airway")
public class AirWayHandler {
    @Autowired(required = false)
    private AirWayRepository airWayRepository;

    @GetMapping("/findAll")
    public List<AirWay> findAll(){
        return airWayRepository.findAll();
    }

    @GetMapping("/findById/{id}")
    public AirWay findById(@PathVariable("id") Long id){
        return airWayRepository.findById(id);
    }

    @PostMapping("/save")
    public void save(@RequestBody AirWay airWay){
        airWayRepository.save(airWay);
    }

    @PutMapping("/update")
    public void update(@RequestBody AirWay airWay){
        airWayRepository.update(airWay);
    }

    @DeleteMapping("/deleteById/{id}")
    public void deleteById(@PathVariable("id") Long id){
        airWayRepository.deleteById(id);
    }
}
